<?php
namespace app\common\model\system;

use app\common\constants\MenuConstant;
use app\common\model\TimeModel;

class SystemMenu extends TimeModel
{

    protected $deleteTime = 'delete_time';
    protected $resultSetType = 'collection';
    //子权限
    public function children()
    {
        return $this->hasMany('app\common\model\system\SystemMenu','pid','id');
    }

    //所有子权限递归
    public function allChilds()
    {
        return $this->children()->with('allChilds');
    }

    //获取路由的meta属性
    public function getMetaAttr($value,$data)
    {

        $data['meta'] = [
          'title'=>$data['title'],
          'icon'=>$data['icon']

        ];
        return $data['meta'];

    }

    /**
     * 定义全局的查询范围
     * @param \think\db\Query $query
     */
    public function scopeApp_id($query)
    {
        return true;
    }

}